{include file="public/header" /}
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('article/category')}">栏目分类</a></li>
        <li class="active">
            <a href="javascript:;">
                {if condition="$params['action'] eq 'edit'" }
                编辑分类
                {else /}
                添加分类
                {/if}
            </a>
        </li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <table class="table table-bordered">
                <tr>
                    <th width="100">所属栏目</th>
                    <td>
                        <select class="form-control" name="parentId" style="width: 200px;">
                            <option value='0' {if condition="$info['ac_parent_id'] eq 0" } selected="selected" {/if} >默认顶级</option>
                            {foreach name="category" item="vo"}
                                <option value='{$vo.id}' {if condition="$vo['id'] eq $info['ac_parent_id']" } selected="selected" {/if} >{$vo.name}</option>
                                {foreach name="$vo['children']" item="vo2"}
                                    <option value='{$vo2.id}' {if condition="$vo2['id'] eq $info['ac_parent_id']" } selected="selected" {/if} >└────{$vo2.name}</option>
                                {/foreach}
                            {/foreach}
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>分类名称<span class="form-required">*</span></th>
                    <td>
                        <input class="form-control" type="text" name="name"
                               id="name" required value="{$info['ac_name']|default=''}" placeholder="请输入文章分类名称"/>
                    </td>
                </tr>
                <tr>
                    <th>排序</th>
                    <td>
                        <input class="form-control" type="text" name="sort"
                               id="sort" required value="{$info['ac_sort']|default='1000'}" placeholder="请输入排序"/>
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <div class="col-sm-offset-2 col-sm-10">
                            <input type="hidden" name="id" value="{$info['ac_id']|default=0}" />
                            <input type="hidden" name="action" value="{$params['action']}" />
                            <button type="submit" class="btn btn-primary js-ajax-submit">提交</button>
                            <a class="btn btn-default" href="{:url('article/category')}">返回</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<script src="/static/admin/js/layer/layer.js"></script>
<script type="text/javascript">
    $(function() {
        $(".js-ajax-submit").click(function () {
            var action = "{$params['action']}";
            $.ajax({
                url: "{:url('article/categoryOperateAjax')}",
                type: "POST",
                data: $(".js-ajax-form").serialize(),
                processData: false,
                contentType: false,
                dataType: 'json',
                async: false,
                success: function (res) {
                    if (res.errorCode === 200) {
                        layer.confirm(res.message, {
                            btn:['确认','取消'],
                            success:function(){
                                this.enterEsc = function (event) {
                                    if (event.keyCode === 13) {
                                        $(".layui-layer-btn0").click();
                                        return false;
                                    }
                                };
                                $(document).on('keydown', this.enterEsc);

                                $(".layui-layer-btn0").on("click",function() {
                                    if (action === "add") {
                                        window.location.href = "{:url('article/categoryOperate')}";
                                    } else {
                                        window.location.href = "{:url('article/category')}";
                                    }
                                    return false
                                })
                            },
                            end:function(){
                                $(document).off('keydown',this.enterEsc);
                            }
                        });
                    } else {
                        layer.alert(res.message, {
                            title: '提示',
                            icon: 2
                        });
                    }
                }
            });
            return false;
        });
    });
</script>

</body>
</html>
